package com.itlong.cloud.operate;

import com.itlong.cloud.project.operate.IOperateU8BaseDataServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.Date;

/**
 * <desc>
 *      运营基础数据与U8同步定时任务调度类
 * </desc>
 *
 * @createDate 2020/12/03
 */
@EnableScheduling // 启用定时任务
@RestController
public class OperateSynchronizeU8BaseDataTimeTask {
    private static Logger LOG = LoggerFactory.getLogger(OperateSynchronizeU8BaseDataTimeTask.class);

    @Autowired
    private IOperateU8BaseDataServiceClient iOperateU8BaseDataServiceClient;


    /**
     * <desc>
     *     运营基础数据与U8同步定时任务
     * </desc>
     *
     * @author Juguang.S
     * @createDate 2020/06/12
     */
    @Scheduled(cron = "0 20 3 * * ?") // 每天凌晨3点20 13点20执行
//    @Scheduled(cron = "0 */5 * * * ?") // 每5分钟同步一次
//    @Scheduled(cron = "0 20 13 ? * *")
    public void timeTaskSynchronizeProductBaseByU8() {

       new Thread(() -> {
           try{
               iOperateU8BaseDataServiceClient.timeTaskSynchronizeBaseDataByU8();
               LOG.info("【定时任务】运营基础数据与U8同步执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"));
           } catch (Exception e) {
               LOG.error("【定时任务】运营基础数据与U8同步执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"), e);
           }
       }).start();

    }

}
